package logic 
{
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.events.Event;
	import gc.events;
	import gc.states;
	
	public class StateMachine extends MovieClip
	{
		private var stageRef:DisplayObjectContainer;
		private var state:String;
		
		public function getState():String
		{
			return state;
		}
		
		private function setState(s:String):void
		{
			//somehow check if its an available state
			state = s;
		}
		
		private function nowbuilding_handler(e:CustomEvent):void
		{
			setState(states.NOW_BUILDING);
		}
		
		private function setfree_handler(e:CustomEvent):void
		{
			setState(states.FREE);
		}
		
		private function init(e:Event):void
		{
			stageRef = parent;
			stageRef.addEventListener(events.NOW_BUILDING, nowbuilding_handler);
			stageRef.addEventListener(events.SET_FREE, setfree_handler);
			dispatchEvent(new CustomEvent(events.SET_FREE));
		}
		
		public function StateMachine() 
		{	
			addEventListener(Event.ADDED_TO_STAGE, init);	
		}
		
	}

}